package com.hutu.tree;

import com.hutu.util.TreeNode;

/**
 * 遍历二叉树，前中后遍历
 *
 * @author hutu
 * @date 2020/12/14 3:11 下午
 */
public class TraverseTree {

    public static void traverseTree(TreeNode root) {
        if (root == null) {
            return;
        }
        // 前序遍历
        System.out.println(root.value);
        traverseTree(root.left);
        // 前序遍历
//        System.out.println(root.value);
        traverseTree(root.right);
        // 前序遍历
//        System.out.println(root.value);
    }

    public static void main(String[] args) {

        TreeNode root = new TreeNode(0,
                new TreeNode(11,
                        new TreeNode(21,
                                new TreeNode(31, null, null),
                                new TreeNode(32, null, null)),
                        new TreeNode(22,
                                new TreeNode(33, null, null),
                                new TreeNode(34, null, null)
                        )
                ),
                new TreeNode(12,
                        new TreeNode(23, null, null),
                        new TreeNode(24, null, null)
                )
        );
        traverseTree(root);
    }
}
